package pro.seac.twitter.web.view;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Component;

import pro.seac.twitter.application.MessageService;
import pro.seac.twitter.application.dto.MessageData;
import pro.seac.twitter.web.Navigateable;
import pro.seac.twitter.web.view.component.MessageList;

import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.Panel;
import com.vaadin.ui.themes.Reindeer;

@Component
@Scope("prototype")
@Navigateable("mention")
@Secured("ROLE_USER")
public class UserMentionView extends BaseView {
	private static final long serialVersionUID = 1L;
	@Autowired
	private MessageService service;
	private MessageList messagesList;

	@Override
	public void enter(ViewChangeEvent event) {
		super.enter(event);
		refreshMessages();
	}

	protected com.vaadin.ui.Component initContent() {
		Panel container = new Panel();
		container.setStyleName(Reindeer.PANEL_LIGHT);
		container.setSizeFull();
		messagesList = new MessageList();
		container.setContent(messagesList);
		return container;
	}

	protected String getTitle() {
		return "Wpisy publiczne";
	}

	public void refreshMessages() {
		List<MessageData> messages = service.getUserMentionedFeedMessages(getCurrentUserId());
		messagesList.refreshMessages(messages);
	}

}
